package com.service.impl;

import com.bean.entity.AnswerInfo;
import com.bean.entity.Certificate;
import com.bean.pojo.PageAssistant;
import com.bean.vo.AnswerInfoVo;
import com.dao.AnswerInfoMapper;
import com.dao.CertificateMapper;
import com.service.AnswerInfoService;
import com.service.CertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 证件基础业务逻辑实现
 */
@Service
public class CertificateServiceImpl implements CertificateService {

    @Autowired
    private CertificateMapper certificateMapper;

    public int save(Certificate t) throws Exception {
        return certificateMapper.insert(t);
    }

    public int remove(Certificate t) throws Exception {
        return certificateMapper.delete(t);
    }

    public int modify(Certificate t) throws Exception {
        return certificateMapper.update(t);
    }

    public Certificate unique(Certificate t) throws Exception {
        List<Certificate> certificateList = certificateMapper.select(t);
        if (certificateList.size()!=1) throw new Exception("您要查询的学生分数暂未找到！");
        return certificateList.get(0);
    }

    public List<Certificate> query(Certificate t) {
        return certificateMapper.select(t);
    }

    public PageAssistant<Certificate> queryByPage(Map<String, Object> map, PageAssistant<Certificate> pa) {
        //查询并设置总记录数
        pa.setCount(certificateMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(certificateMapper.selectByPage(map));
        return pa;
    }
}
